<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
$(function(){	
	$("#createTimeStart").datebox({
		onHidePanel : function() {//datebox把onHidePanel换成onSelect
			onChangeStartTime();
	    }
	});

	$("#createTimeEnd").datebox({
		onHidePanel : function() {//datebox把onHidePanel换成onSelect
			onChangeEndTime();
	    }
	});
	
	//查询按钮绑定点击事件
	$("#searchButton").click(function(){
		$('#docFromTable').datagrid({ queryParams:getParams()});
	});
	

	
	//表格加载
	$('#docFromTable').datagrid({
	    url:'<c:url value="/docIsue/DocIsueListData" />',
	    queryParams:getParams(),//提交参数	    
	    toolbar:'#docisueFromToolbar',//表头工具栏
	    pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    nowrap:false,//列的内容超出所定义的列宽时,自动换行
	    singleSelect:true,
	    columns:[[
			{field:'docId',title:'序号',align:'center',formatter: function(value,row,index){
				return (index+1);
			}},
			{field:'docName',title:'公文标题',width:'35%',formatter: function(value,row,index){
//				var todoUrl="<c:url value='/basic/biaoti/"+row.formId+"/isNew'/>?issueId="+row.issueId; 
//				return "<a href='#' onclick='openDonePage()'>"+value+"</a>";
				return '<a href="#" style="text-decoration:none;color:#2687D0 ;" onclick="openDonePage(\''+row.docId+'\',\''+row.formId+'\')">'+value+'</a>';
			}},
			{field:'formName',title:'文件类型',align:'center',width:'15%'},
			{field:'displayNumber',title:'文号',align:'center'},
			
			{field:'createTime',title:'发文时间',align:'center',formatter: function(value,row,index){
				var fromDate="";
				if(value){
					fromDate=dataFormatStr(new Date(value),"yyyy-MM-dd");
				}
				return fromDate;
			}},
			
			{field:'archiveState',title:'是否归档',align:'center',formatter: function(value,row,index){
				var str="";
				if('1'==value){
					str="已归档";
				}else{
					str="<font color='red'>未归档</font>";
				}
				return str;
			}},
			
			
			{field:'durationUomId',title:'操作',width:70,align:'center',formatter: function(value,row,index){
				var str= "";
				if('1'!=row.archiveState){
					str="<a href=\"#\" class=\"easyui-linkbutton\" plain=\"true\" onclick=\"doFiling('"+row.docId+"');\">归<span class=\"spaceSpan\"></span>档</a>";
				}else{
					str ="无";
				}
				return str;
			}}
	    ]]
	});
});

//执行归档操作
function doFiling(issueId){
	$.ajax({
		   type: "POST",
		   url: "<c:url value='/docIsue/isFiling' />",
		   data: "issueId="+issueId,
		   success: function(msg){
			   if(msg.state=="true"){
				   $.messager.alert('提示',"已归档，无需重复归档！");
			   }else{
				   $.ajax({
					   type: "POST",
					   url: "<c:url value='/docIsue/doFiling' />",
					   data: "issueId="+issueId,
					   success: function(msg){
						   if(msg.state=="200"){
							   $.messager.alert('提示',"归档成功");
							   $('#docFromTable').datagrid({ queryParams:getParams()});
						   }else{
							   $.messager.alert('提示',"归档失败");
						   }
					   }
					});
			   }
		   }
		});
	
}

//查询条件生成方法
function getParams(){
	var jsonObj=new Object();
	if($("#docName").val()!=""){
		jsonObj.docName=$("#docName").val();
	}
	if($("#displayNumber").val()!=""){
		jsonObj.displayNumber=$("#displayNumber").val();
	}
	if($("#createTimeStart").datebox('getValue')!=""){
		jsonObj.createTimeStart=$("#createTimeStart").datebox('getValue')+" 00:00:00";
	}
	if($("#createTimeEnd").datebox('getValue')!=""){
		jsonObj.createTimeEnd=$("#createTimeEnd").datebox('getValue')+" 23:59:59";
	}
	return jsonObj;
}

function openDonePage(issueId,formId){
	var url=_synergyContext+"/basic/donePage?issueId="+issueId+"&formId="+formId; 
	var winFeatures = "height="+(window.screen.height-80)+"px,width="+(window.screen.width-20)+"px,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
	window.open(url,'_blank',winFeatures);
}

function onChangeStartTime(){
	var startTime = $("#createTimeStart").val();//开始时间
	var endTime = $("#createTimeEnd").val();//结束时间
	if(startTime!=null&&startTime!=""&&endTime!=null&&endTime!=""){
		if(startTime>endTime){
			 $.messager.alert('提示','开始时间不能大于结束时间!');
			 $('#createTimeStart').datebox('setValue', ''); 
			 return;
		}
	}	
}

function onChangeEndTime(){
	var startTime = $("#createTimeStart").val();//开始时间
	var endTime = $("#createTimeEnd").val();//结束时间
	if(startTime!=null&&startTime!=""&&endTime!=null&&endTime!=""){
		if(startTime>endTime){
			 $.messager.alert('提示','开始时间不能大于结束时间!');
			 $('#createTimeEnd').datebox('setValue', ''); 
			 return;
		}
	}	
}
